package com.wangjiyuan.giftshuo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.more.PostsBean;
import com.wangjiyuan.giftshuo.utils.RecyclerViewAdapterHelper;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by wjy on 2016/11/22.
 */

public class MoreAdapter extends RecyclerViewAdapterHelper<PostsBean> {
    public MoreAdapter(Context context, List<PostsBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_more, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.Instance(position);

    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private ImageView image;
        private TextView title, time, author, like_count;

        ViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.image);
            title = (TextView) itemView.findViewById(R.id.title);
            time = (TextView) itemView.findViewById(R.id.time);
            author = (TextView) itemView.findViewById(R.id.author);
            like_count = (TextView) itemView.findViewById(R.id.like_count);
            like_count.setOnClickListener(this);
        }

        void Instance(int position) {
            PostsBean postsBean = mList.get(position);

            Date date = new Date(postsBean.getCreatedAt());
            DateFormat calendar = new SimpleDateFormat("MM-dd");
            String format = calendar.format(date);
            time.setText(format);
            title.setText(postsBean.getTitle());
            like_count.setText(postsBean.getLikesCount() + "");
            Glide.with(mContext)
                    .load(postsBean.getCoverImageUrl())
                    .placeholder(mContext.getResources().getDrawable(R.mipmap.post_place_holder_image))
                    .centerCrop()
                    .into(image);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.like_count:
                    break;
            }
        }
    }
}
